package com.qf.cx.simplenms.topic.model;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;

import com.qf.cx.simplenms.readergroup.api.ReaderGroup;
import com.qf.cx.simplenms.tagmemory.model.TagMemoryModel;

public class TopicModel {
	private String name;
	private long cycle;

	private final Set<ReaderGroup> readerGroups = new CopyOnWriteArraySet<>();
	private final Set<TagMemoryModel> tagMemories = new CopyOnWriteArraySet<>();

	public synchronized Set<ReaderGroup> getReaderGroups() {
		return new HashSet<>(readerGroups);
	}

	public synchronized Set<TagMemoryModel> getTagMemories() {
		return new HashSet<>(tagMemories);
	}

	public synchronized String getName() {
		return name;
	}

	public synchronized void setName(String name) {
		this.name = name;
	}

	public synchronized long getCycle() {
		return cycle;
	}

	public synchronized void setCycle(long cycle) {
		this.cycle = cycle;
	}

	public synchronized void deleteTagMemories(Collection<TagMemoryModel> c) {
		this.tagMemories.removeAll(c);
	}

	public synchronized void addTagMemories(Collection<TagMemoryModel> c) {
		this.tagMemories.addAll(c);
	}

	public synchronized void deleteReaderGroups(Collection<ReaderGroup> c) {
		this.readerGroups.removeAll(c);
	}

	public synchronized void addReaderGroups(Collection<ReaderGroup> c) {
		this.readerGroups.addAll(c);
	}

	@Override
	public String toString() {
		return "TopicModel [name=" + name + ", cycle=" + cycle + ", tagMemories=" + tagMemories + "]";
	}
}
